package com.zxl.springcloud.controller;

import com.zxl.springcloud.entity.Student;
import com.zxl.springcloud.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class StudentController {

    @Autowired
    private DiscoveryClient discoveryClient;

    @Autowired
    private StudentService studentService;

    @GetMapping("/discover")
    public String disCover(){
        StringBuilder builder=new StringBuilder();
        discoveryClient.getServices().stream().forEach(e->{
            builder.append(e).append("\t\n");
        });
        return builder.toString();
    }

    @PostMapping("/student/add")
    public boolean add(@RequestBody  Student student){
        return studentService.add(student);
    }

    @GetMapping("/student/get/{id}")
    public Student get(@PathVariable("id") Long id){
        System.out.println("7001被调用");
        return studentService.get(id);
    }


    @GetMapping("/student/findAll")
    public List<Student> findAll(){
        System.out.println("7001被调用");
        return studentService.findAll();
    }
}
